<?php
namespace data\sys\images;
use \data\BaseData;
/**
 * 相册管理
 */
class ImageAlbumData extends BaseData{
    
    /**
     * 读取一个菜单信息
     */
    public function find($param){
        $fields = ['id','tag','uid','utype','status'];
        $where = $this->parseWhere($fields,$param);
        if( !$where )  dataE('查询条件不能为空');
        $info  = M('sys_image_album')->where($where)->find();
        return $info;
    }
    
    /**
     * 列表读取
     */
    public function getList($param){
        $fields = ['id','tag','uid','utype','status'];
        $where = $this->parseWhere($fields,$param);
        if( !$where )  dataE('查询条件不能为空');
        $info  = M('sys_image_album')->where($where)->order('id desc')->select();
        return $info;
    }
    
    /**
     * 添加
     */
    public function add($data){
        $check = [            
            'utype'     => ['reg'=>[1,2,3,4]],
            'uid'       => ['reg'=>'int'],
            'tag'       => '',
            'name'      => ['check'=>'must','msg'=>'相册名称不能为空'],
            'remark'    => '',
            'sort'      => ['def'=>50],
            'addtime'   => ['val'=>SYS_TIME],
            'status'    => ['val'=>1]            
        ];
        $save = $this->verifyData($check,$data);
        return M('sys_image_album')->insertGetId($save);
    }
    
    /**
     * 添加
     */
    public function edit($id,$data){
        if( !$id ) dataE('相册ID不能为空');
        $check = [            
            'utype'     => ['reg'=>[1,2,3,4]],
            'uid'       => ['reg'=>'int'],
            'tag'       => '',
            'name'      => ['msg'=>'相册名称不能为空','reg'=>'must'],
            'remark'    => '',
            'sort'      => '',
            'status'    => ['reg'=>[1,2]]            
        ];
        
        $where = ['id'=> $id];
        $save = $this->verifyData($check,$data);
        $result = M('sys_image_album')->where($where)->update($save);
        if( $result === false ) dataE('修改相册信息失败');
    }
}